package com.mj.servlet;

import com.mj.mapper.StudentMapper;
import com.mj.mybatis.MyHelper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/show.action")
public class Show extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MyHelper<StudentMapper> mh = new MyHelper<StudentMapper>();
        StudentMapper sm = mh.getMapper(StudentMapper.class);
        //MyHelper mh = new MyHelper();
        //StudentMapper sm = mh.getSession().getMapper(StudentMapper.class);
        if (req.getParameter("did")!=null){
            int id = Integer.parseInt(req.getParameter("did"));
            sm.deleteById(id);
        }
        req.setAttribute("student", sm.queryTotal());
        req.getRequestDispatcher("show.jsp").forward(req, resp);
        mh.close();
    }
}
